/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sg.edu.nus.iss.billing.ui.gui;

import java.awt.Font;
import java.beans.PropertyVetoException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JOptionPane;

import sg.edu.nus.iss.billing.ui.controller.OneBillingSystem;

/**
 *
 * @author AdminNUS
 */

public class PreviewBill extends javax.swing.JInternalFrame {

    /**
     * Creates new form PreviewBill
     */
	private OneBillingSystem onebillingsystem;
	private String fileIn;
	
    public PreviewBill(OneBillingSystem onebillingsystem,String fileIn) {
    	this.fileIn = fileIn;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        txtPreviewBill = new javax.swing.JTextArea();
        btnClose = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("View Bill "+fileIn);
        
        txtPreviewBill.setColumns(20);
        txtPreviewBill.setRows(5);
        txtPreviewBill.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        txtPreviewBill.setFont(new Font("Courier",Font.PLAIN,11));
        txtPreviewBill.setWrapStyleWord(true);
        
        jScrollPane1.setViewportView(txtPreviewBill);

        btnClose.setText("Close");
       
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 814, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnClose)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnClose)
                .addGap(0, 11, Short.MAX_VALUE))
        );
        
        try {
            FileReader fr = new FileReader("data//"+fileIn);
            BufferedReader bufRdr = new BufferedReader(fr);
            
            String line = null;
            while ((line = bufRdr.readLine()) != null){
            	txtPreviewBill.append(line);
            	txtPreviewBill.append("\n");
            }
            bufRdr.close();
            
        } catch (IOException ioex) {
        	JOptionPane.showMessageDialog(txtPreviewBill, "Sorry, file cannot found.");
        	return;
        }
        
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
           	 try {
 						setClosed(true);
	  				} catch (PropertyVetoException e) {
	  					// TODO Auto-generated catch block
	  					e.printStackTrace();
	  				}
            }
        });
        
        pack();
    }// </editor-fold>
    
    
    // Variables declaration - do not modify
    private javax.swing.JButton btnClose;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txtPreviewBill;
    // End of variables declaration
}
